// ===============================================
// app_main_scaffold
//
// Create by Will on 2024/12/18 23:50
// Copyright @flutter_base.All rights reserved.
// ===============================================

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../../generated/l10n.dart';
import '../../router/app_router_name.dart';

enum ScaffoldTab { home, profile }

class AppMainScaffold extends StatelessWidget {
  const AppMainScaffold({
    super.key,
    required this.selectedTab,
    required this.child,
  });

  final ScaffoldTab selectedTab;

  final Widget child;

  @override
  Widget build(BuildContext context) => Scaffold(
        body: child,
        bottomNavigationBar: _buildBottomNavigationBar(context),
      );

  // 底部导航
  CupertinoTabBar _buildBottomNavigationBar(BuildContext context) {
    return CupertinoTabBar(
      backgroundColor: Colors.transparent,
      items: <BottomNavigationBarItem>[
        BottomNavigationBarItem(
          icon: const Icon(CupertinoIcons.home),
          label: AppIntl.of(context).app_home,
        ),
        BottomNavigationBarItem(
          icon: const Icon(CupertinoIcons.profile_circled),
          label: AppIntl.of(context).app_profile,
        ),
      ],
      currentIndex: selectedTab.index,
      // activeColor: CupertinoTheme.of(Get.context!).primaryColor,
      border: const Border(
        top: BorderSide(
          color: Colors.transparent,
          width: 0.0, // One physical pixel.
          style: BorderStyle.solid,
        ),
      ),
      onTap: (idx) {
        switch (ScaffoldTab.values[idx]) {
          case ScaffoldTab.home:
            context.go(AppRouterName.home);
            break;
          case ScaffoldTab.profile:
            context.go(AppRouterName.profile);
            break;
        }
      },
    );
  }
}
